package com.cn.sl.server.common.model

import jakarta.persistence.CascadeType
import jakarta.persistence.Column
import jakarta.persistence.FetchType
import jakarta.persistence.JoinColumn
import jakarta.persistence.ManyToOne
import jakarta.persistence.MappedSuperclass
import org.springframework.data.annotation.CreatedDate
import java.time.LocalDateTime

/**
 * 逻辑删除实体父类
 */
@MappedSuperclass
open class SoftDeleteEditableEntity<UserEntity : BaseEntity> : EditableEntity<UserEntity>() {
    /**
     * 删除标记
     */
    @Column(name = "delete_flag")
    open var del: Boolean = false

    @Column(name = "deleted_by")
    var deletedById: Long? = null

    @ManyToOne(fetch = FetchType.LAZY, cascade = [CascadeType.DETACH])
    @JoinColumn(name = "deleted_by", insertable = false, updatable = false)
    var deletedBy: UserEntity? = null

    @CreatedDate
    @Column(updatable = false)
    var deletedTime: LocalDateTime? = null


}